<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>课程信息查询</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            margin: 0;
            padding: 0;
        }
        .container {
            width: 80%;
            margin: 0 auto;
            background-color: #fff;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            margin-top: 20px;
            border-radius: 10px;
        }
        h1 {
            text-align: center;
            color: #333;
        }
        form {
            margin-bottom: 20px;
            text-align: center;
        }
        input[type="text"] {
            padding: 10px;
            width: 200px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        input[type="submit"], select {
            padding: 10px 15px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #4CAF50;
            color: white;
            cursor: pointer;
        }
        input[type="submit"]:hover, select:hover {
            background-color: #45a049;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 10px;
            text-align: center;
        }
        th {
            background-color: #f2f2f2;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        tr:hover {
            background-color: #f1f1f1;
        }
        .pagination {
            text-align: center;
            margin-top: 20px;
        }
        .pagination a {
            color: black;
            padding: 8px 16px;
            text-decoration: none;
            margin: 0 4px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .pagination a:hover {
            background-color: #ddd;
        }
        .page-options {
            display: inline-block;
            margin-left: 20px;
        }
    </style>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            if (!window.location.search) {
                window.location.href = "pagequery?page=1&pageSize=10";
            }
        });
    </script>
</head>
<body>
<div class="container">
    <h1>课程信息查询</h1>
    <form action="${pageContext.request.contextPath}/querybyname" method="get" style="left: -35%;position: relative;top: 10px;">
        <input type="text" name="courseName"  placeholder="请输入课程名称" />
        <input type="submit" value="查询" />
    </form>
    <br/>
    <table>
        <tr>
            <th>课程ID</th>
            <th>教师ID</th>
            <th>课程名称</th>
            <th>上课时间</th>
            <th>教师名称</th>
            <th>学分</th>
        </tr>

        <c:forEach var="course" items="${courses}">
            <tr>
                <td>${course.cid}</td>
                <td>${course.tid}</td>
                <td>${course.cname}</td>
                <td>${course.ctime}</td>
                <td>${course.tname}</td>
                <td>${course.credit}</td>
            </tr>
        </c:forEach>
    </table>
    <div class="pagination">
        <c:if test="${totalPages > 1}">
            <c:forEach var="i" begin="1" end="${totalPages}">
                <a href="pagequery?page=${i}&pageSize=${pageSize}">${i}</a>
            </c:forEach>
        </c:if>
        <div class="page-options">
            <form action="pagequery" method="get">
                每页显示:
                <select name="pageSize" onchange="this.form.submit()">
                    <option value="5" ${pageSize == 5 ? 'selected' : ''}>5</option>
                    <option value="10" ${pageSize == 10 ? 'selected' : ''}>10</option>
                    <option value="15" ${pageSize == 15 ? 'selected' : ''}>15</option>
                </select>
            </form>
        </div>
    </div>
</div>
</body>
</html>
